package com.wxpay.config;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * 配置工具类
 * 用于在静态上下文中访问Spring Bean
 */
@Component
public class ConfigUtils implements ApplicationContextAware {
    
    private static ApplicationContext applicationContext;
    
    @Override
    public void setApplicationContext(ApplicationContext context) throws BeansException {
        applicationContext = context;
    }
    
    /**
     * 获取WxPayConfig实例
     */
    public static WxPayConfig getWxPayConfig() {
        return applicationContext.getBean(WxPayConfig.class);
    }
    
    /**
     * 获取WxPayApiConfig实例
     */
    public static WxPayApiConfig getWxPayApiConfig() {
        return applicationContext.getBean(WxPayApiConfig.class);
    }
    
    // 以下是WxPayConfig的静态代理方法，方便在静态上下文中使用
    
    public static String getMchId() {
        return getWxPayConfig().getMchId();
    }
    
    public static String getApiV3Key() {
        return getWxPayConfig().getApiV3Key();
    }
    
    public static String getAppId() {
        return getWxPayConfig().getAppId();
    }
    
    public static String getSerialNo() {
        return getWxPayConfig().getSerialNo();
    }
    
    public static String getCertPath() {
        return getWxPayConfig().getCertPath();
    }
    
    public static String getPrivateKeyPath() {
        return getWxPayConfig().getPrivateKeyPath();
    }
    
    public static String getWechatPayCertificatePath() {
        return getWxPayConfig().getWechatPayCertificatePath();
    }
    
    // 以下是WxPayApiConfig的静态代理方法
    
    public static String getJsapiPayV3Url() {
        return getWxPayApiConfig().getJsapiPayV3Url();
    }
    
    public static String getNotifyUrl() {
        return getWxPayApiConfig().getNotifyUrl();
    }
    
    public static String getOrderQueryUrl() {
        return getWxPayApiConfig().getOrderQueryUrl();
    }
    
    public static String getRefundUrl() {
        return getWxPayApiConfig().getRefundUrl();
    }
} 